package br.com.almanach.seguranca;

import br.com.almanach.dominio.seguranca.Usuario;
import br.com.almanach.web.Sessao;
import javax.faces.context.FacesContext;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class AlmanachUserDetailsService  implements UserDetailsService {

    public UserDetails loadUserByUsername(String nome) throws UsernameNotFoundException, DataAccessException {        
        Usuario usuario = ((Sessao) FacesContext.getCurrentInstance().
                            getExternalContext().
                            getSessionMap().
                            get("sessao")).getUsuario();
        return new AlmanachUserDetails(usuario);
    }

}